package weekMatch.one_345;

import java.util.HashSet;
import java.util.Set;

public class LeeCode_04 {
    public static void main(String[] args) {

    }
    private static int maxMoves(int[][] grid) {
        int m = grid.length, n = grid[0].length;
        int[] ans = new int[1];
        Set<String> used = new HashSet<>();
        for (int i = 0; i < n; i++) {
            dfs(grid, i, 0, 0, ans, used);
        }
        return ans[0];
    }
    private static void dfs(int[][] grid, int x, int y, int c, int[] count, Set<String> used){
        int m = grid.length, n = grid[0].length;
        count[0] = Math.max(count[0], c);
        String key = x + "," + y;
        if (used.contains(key)){
            return;
        }else {
            used.add(key);
        }
        if (x - 1 >= 0 && y + 1 < n && grid[x - 1][y + 1] > grid[x][y]){
            dfs(grid, x - 1, y + 1, c + 1, count, used);
        }
        if (y + 1 < n && grid[x][y + 1] > grid[x][y]){
            dfs(grid, x, y + 1, c + 1, count, used);
        }
        if (x + 1 < m && y + 1 < n && grid[x + 1][y + 1] > grid[x][y]){
            dfs(grid, x + 1, y + 1, c + 1, count, used);
        }
    }
}
